﻿package com.tomvian.tools
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	
	/**
	 * Cleanup
	 * @author Thomas Vian
	 */
	public class Cleanup extends Object
	{
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public static function cleanDisplayList(doc:DisplayObjectContainer, recursive:Boolean = false):void
		{
			if(doc)
			{
				for(var i:uint = 0, l:uint = doc.numChildren; i < l; i++)
				{
					var mc:DisplayObject = doc.getChildAt(0);
					if(mc is MovieClip) MovieClip(mc).stop();
					
					doc.removeChild(mc);
					
					if(recursive && mc is DisplayObjectContainer) cleanDisplayList(DisplayObjectContainer(mc), true);
				}
			}
		}
	}
}